<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class RewardLog extends Model
{
    protected $table = 'reward_log';

    protected $primaryKey = 'id';

    const CREDIT = 2;//积分

    const REWARD = 1;//金币

    /**
     * 获取信息
     * @param array $where
     * @param array $limit
     * @return mixed
     */
    public static function getByWhere ($where,$limit){
        $collection = static::select(['id', 'params', 'created_at'])->where([
            'user_id' => $where['user_id'],
            'type' => $where['type']
        ])->offset($limit['start'])->limit($limit['length'])->get();

        foreach ($collection as $item){
            $item->source = '提交漏洞';
        }
        return $collection;
    }

    /**
     * 获取总条数
     * @param array $where
     * @return int
     */
    public static function getCount ($where){
        return static::where([
            'user_id' => $where['user_id'],
            'type' => $where['type']
        ])->count();

    }
}
